package net.blogjava.mobile.calendar;

import android.app.Activity;
import android.graphics.Canvas;
import android.view.View;

public class Week extends CalendarParent {
	
	private String[] weekNames;
	private int weekNameColor;

	public Week(Activity activity, View view) {
		super(activity, view);
		weekNameColor = activity.getResources().getColor(R.color.weekname_color);	// 定义一、二、三、四、五的颜色
		weekNames = activity.getResources().getStringArray(R.array.week_name);		// 存放一周的数组：日、一、二、三、四、五、六
		paint.setTextSize(weekNameSize);		// 日历字体大小
	}

	@Override
	public void draw(Canvas canvas) {
		float left = borderMargin;		// 日历边框离屏幕边缘的距离
		float top = borderMargin;
		float everyWeekWidth = (view.getMeasuredWidth() -  borderMargin * 2)/ 7;
		float everyWeekHeight = everyWeekWidth;
		
		paint.setFakeBoldText(true);
		
		for (int i = 0; i < weekNames.length; i++){
			if(i == 0 || i == weekNames.length - 1){	// 判断是否为周末
				paint.setColor(sundaySaturdayColor);	// 是周末显示红色
			}else{
				paint.setColor(weekNameColor);		// 不是周末显示白色
			}
			
			// 求横坐标
			left = borderMargin + everyWeekWidth * i + (everyWeekWidth - paint.measureText(weekNames[i])) / 2;	// measureText返回文件的宽度
			
			// Parameters: 显示的文本内容，横坐标，纵坐标，要显示的样式
			canvas.drawText(weekNames[i], left, top + paint.getTextSize()+weekNameMargin, paint);
		}

	}

}
